package com.terrynoya.fight.stateMachine.controllers
{
	import com.terrynoya.fight.char.Character;
	import com.terrynoya.fight.combat.HitDefinition;
	import com.terrynoya.fight.combat.ProjectTile;
	import com.terrynoya.fight.combat.ProjectileData;
	import com.terrynoya.fight.stateMachine.StateController;
	import com.terrynoya.fight.util.Misc;
	import com.terrynoya.geom.MVector2D;
	
	public class ProjectileCtrl extends HitDef
	{
		private var _projAnimId:int;
		private var _projId:int;
		private var _initVelocity:MVector2D;
		private var _creationOffset:MVector2D;
		private var _acceleration:MVector2D;
		private var _posType:int;
		private var _removeOnHit:Boolean;
		private var _edgebound:int;
		private var _stageBound:int;
		
		
		public function ProjectileCtrl(name:String)
		{
			super(name);
		}
		
		override public function build():void
		{
			super.build();
			this._projAnimId = this.getAttributeAsInt("projanim");
			this._projId = this.getAttributeAsInt("projID");
			this._initVelocity = Misc.getVelocity(this.getAttribute("velocity"));
			this._creationOffset = Misc.getVelocity(this.getAttribute("offset"));
			this._acceleration = Misc.getVelocity(this.getAttribute("accel"));
			this._posType = Misc.getPositionType(this.getAttribute("postype"));
			this._removeOnHit = this.getAttributeAsBoolean("projremove",true);
			this._edgebound = this.getAttributeAsInt("projedgebound");
			this._stageBound = this.getAttributeAsInt("projstagebound");
		}
		
		override public function run(character:Character):void
		{
			var hitDef:HitDefinition = new HitDefinition();
			this.setDifinition(character,hitDef);
			var data:ProjectileData = new ProjectileData();
			data.animationId = this._projAnimId;
			data.creationOffset = this._creationOffset
			data.initialVelocity = this._initVelocity;
			data.accelleration = this._acceleration;
			data.positionType = this._posType;
			data.removeOnHit = this._removeOnHit;
			data.hitDef = hitDef;
			data.stageEdgebound = this._stageBound;
			data.screenEdgebound = this._edgebound;
			data.projcTileId = this._projId;
			
			var projecTile:ProjectTile = new ProjectTile(character.engine,character,data);
			projecTile.engine.entities.add(projecTile);
		}
	}
}